﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<PagedList<PaperSystem.Models.PaperList>>" %>
<%@ Import Namespace="Webdiyer.WebControls.Mvc"%>
<%@ Import Namespace="PaperSystem.Models"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>查看试卷</title>
    <link type="text/css" href="/Content/common.css" rel="Stylesheet" />
    <style type="text/css">
        .col_creator, .col_time, .col_course, .col_usedMinute, .col_paperTitle, .col_TorE{height:100%;text-align:center;}
    </style>
</head>
<body>
    <div class="page_container">
	<div class="page_left">
		<div class="page_left_inner">
			<h1 class="left_logo"><a href="#" class="logo" title="试题库系统">试题库系统</a></h1>
			<%if (ViewData["userName"] != null){%>
			    <div class="left_message">欢迎您，<br/><%=ViewData["userName"]%>老师<br /><a href="/Login/Logout/" class="logout">退出</a></div>
			<%} %>
			<ul class="left_nav">
				<li><a href="/Question/QuestionList">题库管理</a></li>
				<li class="current"><a href="/Paper/PaperList/">试卷管理</a></li>
				<li><a href="/Paper/PaperCorrectList1">改卷</a></li>
				<li><a href="/Statistics/PaperList">统计</a></li>
			</ul>
		</div>
	</div>
	<!-- end page_left -->
	<div class="page_center">
		<div class="page_center_inner">
			<div class="tab_container">
				<ul class="tab_nav">
					<li class="current">查看试卷</li>
					<li><a href="/Paper/PaperAdd">添加试卷</a></li>
				</ul>
			    <div class="tab_content">
				    <div class="tab_content_inner">
				        <form id="form1" action="/Paper/PaperList" style="display:inline;">
                            <label>语种:</label><%=Html.DropDownList("course", ViewData["course"] as SelectList, "全部") %>
                            <label>出卷者:</label><%=Html.TextBox("creator") %>
                            <label>试卷标题:</label><%=Html.TextBox("paperTitle") %>
                            <a href="#" onclick="document.getElementById('form1').submit();" class="btn_blue">查找</a>
				        </form>
				        <form id="form2" action="/Paper/PaperDelete" method="post" style="display:inline;">
			                <input type="hidden" name="course" />
			                <input type="hidden" name="creator" />
			                <input type="hidden" name="paperTitle" />
			                <input type="hidden" name="pid" />
					        <a id="deleteButton" href="#" class="btn_red">删除选中的试卷</a>
				        </form>
				    </div>
			    </div>
			</div>
			<!-- end tab_container -->
			<!-- content begin here -->
			<div class="table_container">
			    <table id="infoTable">
			        <thead>
			            <tr>
			                <th class="col_delete" width="2%"></th>
			                <th class="col_creator" width="10%">出卷者</th>
			                <th class="col_time" width="10%">出卷时间</th>
			                <th class="col_course" width="10%">语种</th>
			                <th class="col_paperTitle" width="40%">试卷名称</th>
			                <th class="col_usedMinute" width="18%">限时（分钟）</th>
			                <th class="col_TorE" width="10%">考试/练习</th>
			            </tr>
			        </thead>
			        <tbody>
			            <% foreach (var item in Model)
                          { %>
                            <tr>
                                <td class="col_delete"><input type="checkbox" /></td>
                                <td class="col_creator"><%=Html.DisplayFor(modelItem => item.creator)%></td>
                                <td class="col_time"><%=Html.DisplayFor(modelItem => item.createTime)%></td>
                                <td class="col_course"><%=Html.DisplayFor(modelItem => item.course)%></td>
                                <td class="col_paperTitle"><%=Html.DisplayFor(modelItem => item.paperTitle)%></td>
                                <td class="col_usedMinute"><%=Html.DisplayFor(modelItem => item.usedMinute)%></td>
                                <td class="col_TorE"><%=Html.DisplayFor(modelItem => item.TorE)%></td>
                                <td class="col_id"><%=Html.HiddenFor(modelItem => item.pid)%></td>
                            </tr>
			            <%} %>
			        </tbody>
			    </table>
			    <%=Html.Pager(Model, new PagerOptions { PageIndexParameterName = "page", PrevPageText = "上一页", NextPageText = "下一页", ShowFirstLast = false, CurrentPagerItemWrapperFormatString = "<span class=\"cur_page_wrap page_wrap\">{0}</span>", NumericPagerItemWrapperFormatString = "<span class=\"page_wrap\">{0}</span>", NavigationPagerItemWrapperFormatString = "<span class=\"page_nav\">{0}</span>", CssClass = "pages clearfix", SeparatorHtml = "" })%>
			</div>
			<!-- content end here -->
			<input type="hidden" id="begin_message" value="<%=TempData["begin_message"] %>"/>
		</div>
	</div>
	<!-- end page_center -->
</div>

<script type="text/javascript" src="/Scripts/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="/Scripts/common.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        //记录选中的行
        var markInfo = '';

        //点击每行选中该行
        var objTable = $('#infoTable');
        objTable.on('click', 'tr:gt(0)', function(event) {
            var tr = $(this);
            //var tr = that.parent().parent('tr');
            var target = $(event.srcElement || event.target);
            if (target.is('input[type=checkbox]')) {
                if (tr.hasClass('selected')) {
                    //如果原来已经选中，则点击后变为不选中，去掉class，并在table中去掉记录
                    tr.removeClass('selected');
                    markTable(objTable, tr.find('td.col_id input'), 'remove');
                } else {
                    //如果原来没选中，则点击后变为选中，加上class，并在table中加上记录，方便上传
                    tr.addClass('selected');
                    markTable(objTable, tr.find('td.col_id input'), 'add');
                }
            } else {
                var pid = tr.find('.col_id input').val();
                location.href = '/Paper/PaperUpdate?pid=' + pid;
            }
        })
        .on('mouseenter', 'tr:gt(0)', function(event) {
            $(this).addClass('hover');
        })
        .on('mouseleave', 'tr:gt(0)', function(event) {
            $(this).removeClass('hover');
        });

        //删除按钮
        var deleteButton = $('#deleteButton');
        deleteButton.on('click', function() {
            var form2creator = $('#form2 input[name=creator]');
            var form2course = $('#form2 input[name=course]');
            var form2paperTitle = $('form2 input[name=paperTitle]');
            var pid = $('#form2 input[name=pid]');
            var form1creator = $('#creator');
            var form1course = $('#course');
            var form1paperTitle = $('#paperTitle');
            form2creator.val(form1creator.val());
            form2course.val(form1course.val());
            form2paperTitle.val(form1paperTitle.val());
            pid.val(markInfo);
            if (markInfo.length == 0) {
                message('请先选中要删除的试卷', 'error', true, 5000);
            } else if (confirm('这将会同时删除所有考生关于该试卷的答案，确认要删除选中的试卷吗?')) {
                document.getElementById('form2').submit();
            }
        });

        /*
        * 定义一些函数
        */

        //标记选中的行
        function markTable(objTable, idCol, action) {
            var strOriginal = markInfo || '';
            var strToFind = idCol.val();
            var array;
            if (strOriginal == '') {
                array = [];
            } else {
                array = strOriginal.split(' ');
            }
            if (action == 'add') {
                for (var i = 0; i < array.length; i++) {
                    if (array[i] == strToFind) {
                        return true;
                    }
                }
                array.push(strToFind);
            } else if (action == 'remove') {
                for (var i = 0; i < array.length; i++) {
                    if (array[i] == strToFind) {
                        array.splice(i, 1);
                    }
                }
            }
            markInfo = array.join(' ');
            return true;
        }
    });
</script>
</body>
</html>
